Allow Liquid logic in recipients too

Andrew Cantino 8 years ago
parent
commit
7e70d507b4
2 changed files with 6 additions and 3 deletions
  1. 2 2
      app/concerns/email_concern.rb
  2. 4 1
      spec/support/shared_examples/email_concern.rb

+ 2 - 2
app/concerns/email_concern.rb

@@ -13,7 +13,7 @@ module EmailConcern
13 13
     if options['recipients'].present?
14 14
       emails = options['recipients']
15 15
       emails = [emails] if emails.is_a?(String)
16
-      unless emails.all? { |email| email =~ Devise.email_regexp || email =~ /\{\{/ }
16
+      unless emails.all? { |email| email =~ Devise.email_regexp || email =~ /\{/ }
17 17
         errors.add(:base, "'when provided, 'recipients' should be an email address or an array of email addresses")
18 18
       end
19 19
     end
@@ -52,4 +52,4 @@ module EmailConcern
52 52
   def present_hash(hash, skip_key = nil)
53 53
     hash.to_a.sort_by {|a| a.first.to_s }.map { |k, v| "#{k}: #{v}" unless k.to_s == skip_key.to_s }.compact
54 54
   end
55
-end
55
+end

+ 4 - 1
spec/support/shared_examples/email_concern.rb

@@ -51,6 +51,9 @@ shared_examples_for EmailConcern do
51 51
       agent.options['recipients'] = '{{ email }}'
52 52
       expect(agent).to be_valid
53 53
 
54
+      agent.options['recipients'] = '{% if x %}a@x{% else %}b@y{% endif %}'
55
+      expect(agent).to be_valid
56
+
54 57
       agent.options['recipients'] = ['bob@example.com', 'jane@example.com']
55 58
       expect(agent).to be_valid
56 59
 
@@ -88,4 +91,4 @@ shared_examples_for EmailConcern do
88 91
       expect(agent.recipients('username' => 'bob', 'domain' => 'example.com')).to eq(["bob@example.com"])
89 92
     end
90 93
   end
91
-end
94
+end